#ifndef __PLAYER_H__
#define __PLAYER_H__

#include "cocos2d.h"
#include "Bag.h"
#include "EquipUI.h"
#include "Unit.h"
//#include "Spell.h"
#include <map>
#include <vector>

USING_NS_CC;

#define SKILL_PRESS_KEY_BUTTON_TAG_START	191
#define SKILL_PRESS_KEY_BUTTON_TAG_END		218
#define DEAD_SCPRITE_TAG 900
#define DEAD_ACTION_TAG 901

enum PlayerAction
{
	STAND,
	WALK,
	DOWN,
	JUMP,
	ATTACK_NORMAL,
	ATTACK_CIRT,
};

enum ItemTextType
{
	NAME_TITLE,
	BONDING_TYPE,
	ATTACK_MODIFY,
	ATTACK_MODIFY_NUMBER,
	REQUIRE_LEVEL,
	REQUIRECLASS_GREEN_HAND,
	REQUIRECLASS_WORRIOR,
	REQUIRECLASS_MAGIC,
	REQUIRECLASS_ACR,
	REQUIRECLASS_THEIF,
	REQUIRECLASS_PIRATE,
	ITEM_VALUES,

	ITEM_TEXTTYPE_END,
};

enum JumpFacing
{
	NONE,LEFT,RIGHT
};
struct Jumper
{
	float		JumpHigh	= 70;
	float		JumpSpeed = 1.0f;
	float		JumpTimer = 1.0f;
	float		JumpStartPointX = 0;
	float		JumpStartPointY = 0;
	JumpFacing	JumpFacing = NONE;
};

typedef std::map<PlayerAction, bool> PlayerDoingActions;
typedef std::map<PlayerAction, CCAnimate*> PlayerActions;

class Item;
class Player : public Unit
{
public:
	explicit Player();
	~Player();
	//Save & Load
	void AddItem(Item* pItem, int Count);
	void AddItem(int Item_Entry, int Count);
	void RemoveItemFromSlot(Slot* pSlot);
	void Revive();
	void SaveToDB();
	void LoadFromDB();
	static void CastFinish();
	void InitBag();
	void CsstFinsh();
	void DoAction(PlayerAction Action, bool Active = true);
	void ResetSprite();
	void Jump(JumpFacing Facing = NONE);
	const std::string GetClassString();
	int GetNextLevelExp();
	//bool IsAttacking()						{ bool attacking = false;  _Attacker == nullptr ? attacking = false : attacking = true; return attacking; }
	//Spell* GetSpell()						{ return _Attacker; }
	//void CastSpell(int Id);
	CCAnimate* GetAction(PlayerAction Action);
	void GetExpReward(int _value);
	void PlayerLevelUp(int _Level = 1);
	void PlayerDead();
	void GetPunish();
	CCLabelTTF* GetItemViewTTF(ItemTextType _ItemTextType);
	void SetCanTakeCrashDamage(bool _val)						{ m_CanDeal_Crash_Damage = _val; }
	void SetUpdatePlayerValue()									{ NeedUpdatePlayerValue = true; }
	void SetEquipBag(EquipUI* _quip)							{ EquipBag = _quip; }
	void SetAttackTime(float value)								{ m_AttackTimer = value; }
	void SetActionTime(float value)								{ m_ActionTimer = value; }
	void SetCanDoAction(bool value)								{ m_CanDoAction = value; }
	void SetFallingSpeed(float f)								{ FallingSpeed = f; }
	void SetMapID(int _Id)										{ SetInt32Value(MAP_ID, _Id); }
	void SetHeath(int _val)										{ SetInt32Value(VALUE_HP,_val); }
	void ModifyMoney(int _val)									{ m_Player_Int32Values[MONEY] = m_Player_Int32Values[MONEY] + _val; }
	void SetInt32Value(Int32Value _val, int Number)				{ m_Player_Int32Values[_val] = Number; UpdatePlayerValue(); }
	bool CanTakeCrashDamage()									{ return m_CanDeal_Crash_Damage; }
	const int GetMoney()										{ return m_Player_Int32Values[MONEY]; }
	float GetAttackTime()										{ return m_AttackTimer; }
	float GetActionTime()										{ return m_ActionTimer; }
	bool IsDisableFall()										{ return m_DisableFall; }
	bool IsJumping()											{ return m_IsJumping; }
	Bag* GetBag()												{ return PlayerBag; }
	EquipUI* GetEquipBag()										{ return EquipBag; }
	float GetFallingSpeed()										{ return FallingSpeed; }
	Rect GetPos()												{ return boundingBox(); }
	const int GetInt32Value(Int32Value _val)					{ return m_Player_Int32Values[_val]; }
	const ClassID GetClass()									{ return (ClassID)m_Player_Int32Values[CLASS]; }
	const int GetLevel()										{ return m_Player_Int32Values[VALUE_LEVEL]; }
	const int GetMapId()										{ return m_Player_Int32Values[MAP_ID]; }
	int GetHeath()												{ return m_Player_Int32Values[VALUE_HP]; }
	int  GetTotalValueNumber(int _ItemValue);

	//Announce
	void SendNotify(std::string _noti);
	//Moving
	bool CanEquipItem(int _slot, Item* pItem);
private:
	virtual void update(float diff);
	int CalcPlayerTotalValue(int _ItemValue);
	void UpdatePlayerValue();
	void CallDeadTalkClass();
	//Spell* _Attacker;

private:
	bool NeedUpdatePlayerValue;
	PlayerActions _PlayerActions;
	PlayerDoingActions _PlayerDoingActions;
	float m_Crash_Damage_Timer;
	bool m_CanDeal_Crash_Damage;
	float m_ActionTimer;
	bool m_CanDoAction;
	bool m_DisableFall;
	bool m_IsJumping;
	float BaseJumpHigh;
	float m_AttackTimer;
	float FallingSpeed;
	Bag* PlayerBag;
	EquipUI* EquipBag;
	CCSprite* ItemViewWindow_Main;
	CCSprite* ItemViewWindow_Sult;
	CCSprite* ItemViewWindow_SultView;
	CCSprite* ItemView_BigImage;
	std::map<ItemTextType, CCLabelTTF*> ItemViewTexts_MainViewWindow;
	Jumper* _Jumper;
	int m_CastingSpell;
	std::map<Int32Value, int> m_Player_Int32Values;
	float m_SaveToDBDelay;
};


#endif